package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController     //等同于同时加上了@Controller和@ResponseBody
public class HelloController {

    //访问/hello或者/hi任何一个地址，都会返回一样的结果
    @RequestMapping(value = {"/hello", "/hi"}, method = RequestMethod.GET)
    public String say() {
        return "hi you!!!";
    }

//    @Value("${girl.name}")
//    private String name;
//
//    //访问/hello或者/hi任何一个地址，都会返回一样的结果
//    @RequestMapping(value = {"/name"}, method = RequestMethod.GET)
//    public String info() {
//        return name;
//    }

    @Autowired
    private UserService userService;

    //访问/hello或者/hi任何一个地址，都会返回一样的结果
    @RequestMapping(value = {"/getUser"}, method = RequestMethod.GET)
    public String getUser(@RequestParam Integer id) {
        if (id==null)
            return null;
        return userService.Sel(id).toString();
    }

}